package com.by.charpter03.services;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.by.charpter03.R;

import androidx.appcompat.app.AppCompatActivity;

public class ServiceActivity extends AppCompatActivity implements View.OnClickListener {

    private Button btn_bind, btn_call, btn_unbind, btn_start, btn_stop;

    String TAG = ServiceActivity.class.getSimpleName();




    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.service_main);
        init();
        Log.d(TAG, Thread.currentThread().getName());


    }

    @Override
    protected void onResume() {
        super.onResume();

    }

    private void init() {
        btn_bind = findViewById(R.id.btn_bind);
        btn_call = findViewById(R.id.btn_call);
        btn_unbind = findViewById(R.id.btn_unbind);
        btn_start = findViewById(R.id.btn_start);
        btn_stop = findViewById(R.id.btn_stop);
        //设置3个按钮的点击监听事件
        btn_bind.setOnClickListener(this);
        btn_call.setOnClickListener(this);
        btn_unbind.setOnClickListener(this);
        btn_start.setOnClickListener(this);
        btn_stop.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_bind:
                //“绑定服务”按钮点击事件

                break;
            case R.id.btn_call:
                //“调用服务中的方法”按钮点击事件

                break;
            case R.id.btn_unbind:
                //“解绑服务”按钮点击事件

                break;
            case R.id.btn_start:

                startService(new Intent(ServiceActivity.this,StartService.class));

                break;
            case R.id.btn_stop:
                stopService(new Intent(ServiceActivity.this,StartService.class));
                break;


        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy");
    }
}

